package com.tencent.trtcplugin;

import android.content.Context;

import androidx.annotation.NonNull;

import com.tencent.live.beauty.custom.ITXCustomBeautyProcesserFactory;
import com.tencent.trtcplugin.utils.TRTCLogger;
import com.tencent.trtcplugin.view.TRTCPlatformViewFactory;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.platform.PlatformViewRegistry;

public class TRTCPlugin implements FlutterPlugin {
    public static final String TAG = "trtc-flutter";
    
    private static ITXCustomBeautyProcesserFactory sProcessFactory;
    
    public static ITXCustomBeautyProcesserFactory getBeautyProcesserFactory() {
        return sProcessFactory;
    }
    
    public static void setBeautyProcesserFactory(ITXCustomBeautyProcesserFactory factory) {
        sProcessFactory = factory;
    }

    private TRTCCloudManager mCloudManager;

    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
        Context context = flutterPluginBinding.getApplicationContext();
        MethodChannel methodChannel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "TencentRTCffi");
        mCloudManager = new TRTCCloudManager(context, methodChannel);

        PlatformViewRegistry registry = flutterPluginBinding.getPlatformViewRegistry();
        registry.registerViewFactory("TRTCPlatformView", new TRTCPlatformViewFactory(flutterPluginBinding.getBinaryMessenger()));
        System.loadLibrary("liteavsdk");
        System.loadLibrary("tencent_rtc_ffi");
    }

    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
        mCloudManager.release();
    }
}